﻿namespace Baddies
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Baddies.Events;
    using Baddies.Nodes;

    /// <summary>
    /// Computes the requests made to the game console.
    /// </summary>
    public class Console : Node
    {
        /// <summary>
        /// Initializes a new instance of the Console class.
        /// </summary>
        public Console() : base()
        {
            EventManager.GetEV.Register("ConsoleMsg", this.ConsoleMsgEventDelegate);
        }

        /// <summary>
        /// Delegate function for the ConsoleMsg event.
        /// </summary>
        /// <param name="sender">Sender of the request.</param>
        /// <param name="e">AddLineArg parameter.</param>
        private void ConsoleMsgEventDelegate(object sender, EventArgs e)
        {
            string text = ((ConsoleMsgArg)e).Text;

            switch (text)
            {
                case "PEEK LOG":
                    {
                        PeekLogArg arg = new PeekLogArg();
                        arg.PeekLog = true;
                        EventManager.GetEV.Trigger("PeekLog", this, arg);
                        break;
                    }

                case "UNPEEK LOG":
                    {
                        PeekLogArg arg = new PeekLogArg();
                        arg.PeekLog = false;
                        EventManager.GetEV.Trigger("PeekLog", this, arg);
                        break;
                    }

                case "PRINT TREE":
                    {                        
                        EventManager.GetEV.Trigger("PrintTree");
                        break;
                    }

                default:
                    {
                        AddLineArg arg = new AddLineArg();
                        arg.Text = "No such command: " + text;
                        EventManager.GetEV.Trigger("AddLine", this, arg);
                        break;
                    }
            }
        }
    }
}
